Go strings 发表于 2018-06-22 | 分类于 Go 对 golang 的标准库进行一个系列性的总结,备查更加方便 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133------------------------------------------------------------strings 包与 bytes 包中的函数用法基本一样,不再赘述。只对 Replacer 进行说明。------------------------------------------------------------// 转换func ToUpper(s string) stringfunc ToLower(s string) stringfunc ToTitle(s string) stringfunc ToUpperSpecial(_case unicode.SpecialCase, s string) stringfunc ToLowerSpecial(_case unicode.SpecialCase, s string) stringfunc ToTitleSpecial(_case unicode.SpecialCase, s string) stringfunc Title(s string) string------------------------------// 比较func Compare(a, b string) intfunc EqualFold(s, t string) bool------------------------------// 清理func Trim(s string, cutset string) stringfunc TrimLeft(s string, cutset string) stringfunc TrimRight(s string, cutset string) stringfunc TrimFunc(s string, f func(rune) bool) stringfunc TrimLeftFunc(s string, f func(rune) bool) stringfunc TrimRightFunc(s string, f func(rune) bool) stringfunc TrimSpace(s string) stringfunc TrimPrefix(s, prefix string) stringfunc TrimSuffix(s, suffix string) string------------------------------// 拆合func Split(s, sep string) []stringfunc SplitN(s, sep string, n int) []stringfunc SplitAfter(s, sep string) []stringfunc SplitAfterN(s, sep string, n int) []stringfunc Fields(s string) []stringfunc FieldsFunc(s string, f func(rune) bool) []stringfunc Join(a []string, sep string) stringfunc Repeat(s string, count int) string------------------------------// 子串func HasPrefix(s, prefix string) boolfunc HasSuffix(s, suffix string) boolfunc Contains(s, substr string) boolfunc ContainsRune(s string, r rune) boolfunc ContainsAny(s, chars string) boolfunc Index(s, sep string) intfunc IndexByte(s string, c byte) intfunc IndexRune(s string, r rune) intfunc IndexAny(s, chars string) intfunc IndexFunc(s string, f func(rune) bool) intfunc LastIndex(s, sep string) intfunc LastIndexByte(s string, c byte) intfunc LastIndexAny(s, chars string) intfunc LastIndexFunc(s string, f func(rune) bool) intfunc Count(s, sep string) int------------------------------// 替换func Replace(s, old, new string, n int) stringfunc Map(mapping func(rune) rune, s string) string------------------------------------------------------------type Reader struct { ... }func NewReader(s string) *Readerfunc (r *Reader) Read(b []byte) (n int, err error)func (r *Reader) ReadAt(b []byte, off int64) (n int, err error)func (r *Reader) WriteTo(w io.Writer) (n int64, err error)func (r *Reader) Seek(offset int64, whence int) (int64, error)func (r *Reader) ReadByte() (byte, error)func (r *Reader) UnreadByte() errorfunc (r *Reader) ReadRune() (ch rune, size int, err error)func (r *Reader) UnreadRune() errorfunc (r *Reader) Len() intfunc (r *Reader) Size() int64func (r *Reader) Reset(s string)------------------------------------------------------------type Replacer struct { ... }// 创建一个替换规则,参数为“查找内容”和“替换内容”的交替形式。// 替换操作会依次将第 1 个字符串替换为第 2 个字符串,将第 3 个字符串// 替换为第 4 个字符串,以此类推。// 替换规则可以同时被多个例程使用。func NewReplacer(oldnew ...string) *Replacer// 使用替换规则对 s 进行替换并返回结果。func (r *Replacer) Replace(s string) string// 使用替换规则对 s 进行替换并将结果写入 w。// 返回写入的字节数和遇到的错误。func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error)------------------------------------------------------------ 打赏 微信支付 支付宝